package com.netease.financial.mapper;

import com.google.gson.Gson;
import com.netease.financial.base.login.LoginViewModel;
import com.netease.financial.base.splash.SplashViewModel;
import com.netease.financial.domain.model.AppUpdate;
import com.netease.financial.domain.model.LaunchPage;
import com.netease.financial.domain.model.Login;
import com.netease.financial.domain.model.PageInfo;
import com.netease.financial.domain.model.UnreadMessageCount;
import com.netease.financial.internal.di.ActivityScope;
import com.netease.financial.viewmodel.AppUpdateViewModel;
import com.netease.financial.viewmodel.UnreadMessageCountViewModel;

import javax.inject.Inject;

/**
 * Mapper class used to transform model in the domain layer to viewModel in the
 * presentation layer.
 */

@ActivityScope
public class NfsViewModelDataMapper {

   private final Gson gson;

    @Inject
    public NfsViewModelDataMapper() {
        this.gson = new Gson();
    }

    public AppUpdateViewModel transform(AppUpdate model) {
        AppUpdateViewModel viewModel = new AppUpdateViewModel();
        viewModel.setApkUrl(model.getApkUrl());
        viewModel.setAppName(model.getAppName());
        viewModel.setChangeLog(model.getChangeLog());
        viewModel.setForceUpdate(model.isForceUpdate());
        viewModel.setUpdateTips(model.getUpdateTips());
        viewModel.setVersionCode(model.getVersionCode());
        viewModel.setVersionName(model.getVersionName());
        return viewModel;
    }

    public UnreadMessageCountViewModel transform(UnreadMessageCount model) {
        UnreadMessageCountViewModel viewModel = new UnreadMessageCountViewModel();
        viewModel.setCount(model.getCount());
        return viewModel;
    }

    public SplashViewModel transform(LaunchPage model) {
        SplashViewModel viewModel = new SplashViewModel();
        viewModel.setDuration(model.getDuration());
        viewModel.setLaunchPageImageUrl(model.getLaunchPageImageUrl());
        viewModel.setAgreementUrl(model.getAgreementUrl());
        return viewModel;
    }

    public LoginViewModel transform(Login model) {
        LoginViewModel viewModel = new LoginViewModel();
        viewModel.setAlias(model.getAlias());
        viewModel.setAccessToken(model.getAccessToken());
        return viewModel;
    }

    public <T> T transform(PageInfo model, Class<T> classOfT) {
        return this.gson.fromJson(model.getContent(), classOfT);
    }

}
